//
//  GSGetPasswordViewController.m
//  GameSky
//
//  Created by lanou on 16/1/19.
//  Copyright © 2016年 NiRongfei. All rights reserved.
//

#import "GSGetPasswordViewController.h"

@interface GSGetPasswordViewController () <UITextFieldDelegate>

@property (nonatomic, strong)UITextField *userNameTextField;

@end

@implementation GSGetPasswordViewController
#pragma mark-------------视图加载完成------------------
- (void)viewDidLoad {
    [super viewDidLoad];
    // 夜间模式
    self.view.dk_backgroundColorPicker = DKColorWithRGB(0xffffff, 0x343434);
    
    self.navigationItem.title = @"用户登录";
// 添加子视图
    [self addSubViews];
}
#pragma mark------------添加子视图-------------------
- (void)addSubViews{
// 用户名输入框
    self.userNameTextField = [[UITextField alloc] initWithFrame:CGRectMake(20, 64 + 20, kScreenWidth - 40, 42)];
    // 左视图
    UIImageView *imageVUser = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 42, 42)];
    imageVUser.backgroundColor = [UIColor purpleColor];
    _userNameTextField.leftView = imageVUser;
    _userNameTextField.leftViewMode = UITextFieldViewModeAlways;
    //代理
    _userNameTextField.delegate = self;
    _userNameTextField.borderStyle = UITextBorderStyleRoundedRect;
    _userNameTextField.placeholder = @"请输入用户名";
    // clear按钮
    _userNameTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    [self.view addSubview:_userNameTextField];
// 提交button
    UIButton *button = [UIButton buttonWithType:(UIButtonTypeCustom)];
    button.frame = CGRectMake(_userNameTextField.left, _userNameTextField.bottom + 14, _userNameTextField.width, _userNameTextField.height);
    button.backgroundColor = [UIColor redColor];
    [button setTitle:@"提交" forState:(UIControlStateNormal)];
    [button setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:button];
}
#pragma mark----------------button点击-------------- 
- (void)buttonAction:(UIButton *)button{
   // 构建网络请求参数字典
    NSDictionary *dic = @{@"request":@{@"username":_userNameTextField.text}
                          };
    
  [GSNetworkManager requestWithUrlStr:kGetPassword paraDict:dic method:POST success:^(NSURLResponse *response, NSData *data) {
      if (data) {
//          NSMutableDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableLeaves) error:nil];
          
          
      }
  } failure:^(NSError *error) {
      
  }];

}
#pragma mark----------------回收键盘-----------------
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}
#pragma mark------------------------------------------
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
